<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  PaymentTransfer.php 2018-05-24 18:54 cunx $
   
*/

namespace common\library\wechat\payment;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;

/**
 * 微信企业打款
 * Class PaymentTransfer
 * @package common\library\wechat\payment
 * @author cunx
 */
class PaymentTransfer extends WechatApi
{
    static $apiType = 'payment';
    static $paymentId = 0;
    /**
     * 打款到余额
     * @param array $transferParams
     * -----------------------------------------------------------------------------------
     * $transferParams[partner_trade_no]    商户订单号，需保持唯一性
     * $transferParams[openid]              商户appid下，某用户的openid
     * $transferParams[check_name]          NO_CHECK：不校验真实姓名 / FORCE_CHECK：强校验真实姓名
     * $transferParams[re_user_name]        收款用户真实姓名
     * $transferParams[amount]              企业付款金额，单位为分
     * $transferParams[desc]                企业付款操作说明信息，必填
     * ------------------------------------------------------------------------------------
     * @return array|bool|void
     * @author cunx
     */
    public static function toBalance(array $transferParams)
    {
        try {
            $result = self::getInstance()->transfer->toBalance($transferParams);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 查询余额打款
     * @param string $partnerTradeNo    商户订单号
     * @return array|bool|void
     * @author cunx
     */
    public static function queryBalanceOrder(string $partnerTradeNo)
    {
        try {
            $result = self::getInstance()->transfer->queryBalanceOrder($partnerTradeNo);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 打款到银行卡（需要配置PKCS#8的公钥文件）
     * @param array $transferParams
     * --------------------------------------------------------------------------------------
     * $partnerTradeNo[partner_trade_no]    商户订单号，需保持唯一性
     * $partnerTradeNo[enc_bank_no]         收款方银行卡号
     * $partnerTradeNo[enc_true_name]       收款方用户名
     * $partnerTradeNo[bank_code]           银行卡所在开户行编号
     * $partnerTradeNo[amount]              企业付款金额，单位为分（支付总额，不含手续费）
     * $partnerTradeNo[desc]                企业付款到银行卡付款说明,即订单备注（UTF8编码，允许100个字符以内）
     * --------------------------------------------------------------------------------------
     * @附录 @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_4&index=5 银行编号列表
     * --------------------------------------------------------------------------------------
     * @return array|bool|void
     * @author cunx
     */
    public static function toBankCard(array $transferParams)
    {
        try {
            $result = self::getInstance()->transfer->toBankCard($transferParams);
        } catch (\Exception $result) {}
        return Wechat::apiError($result);
    }

    /**
     * 查询银行打款
     * @param string $partnerTradeNo    商户订单号
     * @return array|bool|void
     * @author cunx
     */
    public static function queryBankCardOrder(string $partnerTradeNo)
    {
        try {
            $result = self::getInstance()->transfer->queryBankCardOrder($partnerTradeNo);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

}